package com.youfang.sixthmedia.common;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.gzit.utils.AndroidUtils;
import com.youfang.sixthmedia.R;
import com.youfang.sixthmedia.controller.HeaderController.HeaderAdapter;
import com.youfang.sixthmedia.message.model.Buddy;

public class BuddyAdapter extends HeaderAdapter<Buddy> {

	public BuddyAdapter(Context context) {
		super(context, R.layout.buddy_item);
	}

	// 直接返回postion有没有什么问题？
	public long getItemId(int position) {
		return this.getItem(position).innerID;
	}

	@Override
	protected void render(Buddy item, View view) {

		ImageView logo = (ImageView) view.findViewById(R.id.logo);
		logo.setImageBitmap(item.logoBitmap);

		// other info
		TextView nickname = (TextView) view.findViewById(R.id.nickname);
		AndroidUtils.boldText(nickname);
		nickname.setText(item.nickname);
		AndroidUtils.boldText(nickname);
		//
		TextView introduce = (TextView) view.findViewById(R.id.introduce);
		introduce.setText(item.introduce);

		TextView distance = (TextView) view.findViewById(R.id.distance);

		distance.setText(YouFangUtils.getDistanceDesc(item.distance));

		// show unreaded message
		TextView status = (TextView) view.findViewById(R.id.status);
		if (item.showMessageCnt) {
			status.setVisibility(item.unreadcount == 0 ? View.INVISIBLE
					: View.VISIBLE);
			status.setText("" + item.unreadcount);
		} else {
			status.setVisibility(View.INVISIBLE);
		}

	}

}